<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function Parent(name) {
            this.name = name || '干饭人';
            this.run = function () {
                console.log(this.name + '干饭');
            }
        }
        Parent.prototype.say = function () {
            console.log('我是' + this.name);
        } 

        function Child(name,time){
            //在子类构造函数中通过Parent.call(this),继承父类的属性
            Parent.call(this,name);
            this.time = time || '十二点';
        }
        //Object.create()方法创建一个新对象，使用现有的对象来提供新创建的对象的__proto__。
        //子类继承父类的原型
        Child.prototype = Object.create(Parent.prototype);
        Child.prototype.constructor = Child;
        
        let son = new Child('干饭魂','十二点');
        son.run();//干饭魂干饭
        son.say();//我是干饭魂
        console.log(son.time);//十二点
    </script>
</body>

</html>